package com.ruoyi.study.strategy.impl;

import com.ruoyi.study.api.domain.StudySummaryDTO;
import com.ruoyi.study.strategy.PushStrategy;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component("emailPushStrategy") // 策略标识，用于上下文选择
public class EmailPushStrategy implements PushStrategy {
    @Resource
    private JavaMailSender javaMailSender;

    // 发件人邮箱（需配置）
    private String fromEmail = "756133452@qq.com";
    // 收件人邮箱（需配置）
    private String toEmail = "732030509@qq.com";

    @Override
    public void push(StudySummaryDTO dto) {
        SimpleMailMessage message = new SimpleMailMessage();
        message.setFrom(fromEmail);
        message.setTo(toEmail);
        message.setSubject("每日学习总结与计划");
        message.setText(String.format(
                "【学习总结】%s（日期：%tF）\n【今日计划】%s（日期：%tF）",
                dto.getSummaryContent(), dto.getSummaryDate(),
                dto.getPlanContent(), dto.getPlanDate()
        ));
        javaMailSender.send(message);
    }
}